package com.neusoft.SPNursingHome.service;

import com.neusoft.SPNursingHome.dao.ClientCareItemDao;
import com.neusoft.SPNursingHome.po.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClientCareItemServiceImpl implements ClientCareItemService {
    @Autowired
    private ClientCareItemDao clientCareItemDao;

    // 查看客户护理项目列表
    @Override
    public ResponseBean<List<ClientCareItem>> listClientCareItem() {
        // TODO
        return new ResponseBean<>();
    }
    // 添加客户护理项目(单个，批量TODO)
    @Override
    public ResponseBean<Integer> addClientCareItem(ClientCareItem clientCareItem) {
        return null;
    }

    // 批量添加客户护理项目
    @Override
    public ResponseBean<Integer> batchInsertClientCareItems(List<ClientCareItem> clientCareItems) {
        int saveResult = clientCareItemDao.insertBatch(clientCareItems);
        if (saveResult > 0) {
            return new ResponseBean<>(saveResult);
        } else {
            return new ResponseBean<>(500, "批量添加客户护理项目失败");
        }
    }

    // 移除客户护理项目
    @Override
    public ResponseBean<Integer> deleteCareItem(Integer clientCareItemId) {
        int saveResult = clientCareItemDao.deleteById(clientCareItemId);
        if (saveResult > 0) {
            return new ResponseBean<>(saveResult);
        } else {
            return new ResponseBean<>(500, "移除客户护理项目失败");
        }
    }

    // 根据客户id查看客户护理项目列表
    @Override
    public ResponseBean<List<ClientCareItemWithCareLevelAndCareItem>> getClientCareItemsByClientId(Integer clientId) {
        List<ClientCareItemWithCareLevelAndCareItem> clientCareItems = clientCareItemDao.getClientCareItemsByClientId(clientId);
        return new ResponseBean<>(clientCareItems);
    }

    // 根据项目编号、项目名称模糊查询客户护理项目
    public ResponseBean<List<ClientCareItem>> getClientCareItemByConditions(String careItemCode, String careItemName) {
        return null;
    }

    // 更新客户护理项目
    @Override
    public ResponseBean<Integer> updateClientCareItem(ClientCareItem clientCareItem) {
        System.out.println(clientCareItem.getClientCareItemId());
        int saveResult = clientCareItemDao.updateById(clientCareItem.getClientCareItemId(),clientCareItem.getServiceCount(),clientCareItem.getServiceEndDate());
        if (saveResult > 0) {
            return new ResponseBean<>(saveResult);
        } else {
            return new ResponseBean<>(500, "更新（续费）客户护理项目失败");
        }
    }
}
